const app = getApp()
const db = wx.cloud.database()
Page({
  //页面的初始数据
  data: {
    shuaxin: "",
    search: "",
    movehight: 500,
    movehight2: 500,
    jianting: false,
    index: -1,
    kong: false,
    user: 1,
  },

  // 生命周期函数--监听页面加载
  onLoad: function (options) {

    var tjid = options.id
    var fenxiang = options.fenxiang
    var liuyan = options.liuyan
    app.fenxiang = "false"
    /*调用云函数登录*/
    wx.showLoading({
      title: '登录中',
      mask: true
    })
    wx.getUserProfile({
      desc: '展示用户信息', // 声明获取用户个人信息后的用途，后续会展示在弹窗中，请谨慎填写
      success: (res) => {
        app.golobalData.userInfo1 = res.userInfo
      }
    })
    wx.cloud.callFunction({
      name: 'login',
      data: {}
    }).then((res) => {
      db.collection("jnjp_user").where({
        _openid: res.result.openid
      }).get().then((res) => {
        app.userInfo = Object.assign(app.userInfo, res.data[0]);
        // console.log(app.userInfo.userinfo.user)
        this.setData({
          user: app.userInfo.userinfo.user
        })
        wx.hideLoading()
        if (app.userInfo._openid == "") {
          /*如果没有登录信息则跳转到wd*/
          wx.switchTab({
            url: "../my/wd/wd"
          })
          //如果没有登录信息则提示未登录
          wx.showToast({
            title: '未登录只可浏览',
            icon: 'none',
            duration: 3000
          })
        } else {
          //登录上了就监听user
          this.jianting()
          this.setData({
            jianting: true,
          })
        }
        if (tjid != "" && tjid != undefined && tjid != null) {
          wx.navigateTo({
            url: "../xiangqing/xiangqing?id=" + tjid + "&fenxiang=" + fenxiang + "&liuyan=" + liuyan
          })
        }
      })
    });

    var systeminfo = wx.getSystemInfoSync()
    this.setData({
      movehight: systeminfo.windowHeight,
      movehight2: systeminfo.windowHeight - 100
    })
  },
  // 获取滚动条当前位置
  onPageScroll: function (e) {},
  //刷新
  shuaxin() {},
  //生命周期函数--监听页面初次渲染完成
  onReady: function () {},

  //生命周期函数--监听页面显示！！！！！！！！！！！！！！
  onShow: function () {
    this.setData({
      user: app.userInfo.userinfo.user
    })
    //这是发帖成功，跳转刷新

  },
  //刷新消息红点(用于更新非tabar页面未设置的红点)

  //生命周期函数--监听页面隐藏
  onHide: function () {},

  //生命周期函数--监听页面卸载
  onUnload: function () {},

  //页面上拉触底事件的处理函数
  onReachBottom: function () {},

  //用户点击右上角分享
  onShareAppMessage: function () {},

  //页面上拉触底事件的处理函数
  onReachBottom: function () {},
  //返回组件Tabs的监听
  changetitle(e) {

  },
  //下拉动作-刷新
  onPullDownRefresh: function () {
    this.shuaxin()
    //setTimeout(function (){wx.stopPullDownRefresh({})},'2000')
  },
  jianting() {},
  jiantingchuli(e) {},
  adddetail: function () {
    wx.navigateTo({
      url: '../post/post',
    })
  }
})